//
// Created by 17775 on 2024/7/30.
//

#ifndef RAYCI_CCDIMAGEDATA_H
#define RAYCI_CCDIMAGEDATA_H

#include <QVector>
#include "IGeneralCalibration.h"

template<typename T>
class CCDImageData {
    std::shared_ptr<IGeneralCalibration> _xCalibration = nullptr;
    unsigned _width;
    unsigned _height;
    QVector<T> _yData;
    QVector<T> _xData;
public:
    CCDImageData(unsigned width, unsigned  height) : _width(width),
                                                     _height(height), _yData(width * height, T()), _xData() {
        _xData.reserve(width);
        for(int i = 0; i < width; ++i) {
            _xData.emplaceBack(i);
        }
    }

    const QVector<T>& YData() const {
        return _yData;
    }

    const QVector<T>& XData() const {
        return _xData;
    }

    auto getWidth() const noexcept{
        return _width;
    }

    auto getHeight() const noexcept{
        return _height;
    }

    bool getValue(int rowIndex, int columnIndex, T &value) const {
        if(rowIndex < 0 || columnIndex < 0 || rowIndex >= _height || columnIndex >= _width ) return false;
        unsigned index = rowIndex * _width + columnIndex;
        value = _yData.at(index);
        return true;
    }

    bool setValue(int rowIndex, int columnIndex, T value) {
        if(rowIndex < 0 || columnIndex < 0 || rowIndex >= _height || columnIndex >= _width) return false;
        unsigned index = rowIndex * _width + columnIndex;
        _yData.replace(index, value);
        return true;
    }
};


#endif //RAYCI_CCDIMAGEDATA_H
